home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / MUIRexx / demos / MUIRexxDir / renfile.rexx < prev   
OS/2 REXX Batch file  |  1997-04-27  |  3KB  |  93 lines

  1. /*
  2.  
  3. Code:       renfile.rexx
  4. Author:     Russell Leighton
  5. Revision:   11 Jan 1996
  6.  
  7. Comments:   
  8.  
  9. */
  10.  
  11. options results
  12.  
  13. /* TAG ID definitions */
  14.  
  15. Weight =                          0x80421d1f /* V4  i.. WORD              */
  16. Dirlist_Directory =               0x8042ea41 /* V4  isg STRPTR            */
  17. Dirlist_RejectIcons =             0x80424808 /* V4  is. BOOL              */
  18.  
  19. parse arg portname' ['sfile']' '['dfile']'
  20.  
  21. call pragma('Directory','muidir:')
  22.  
  23. address VALUE portname
  24.  
  25. group ID DIR REGISTER
  26. ndir = result
  27.  
  28. if dfile ~= '' then do
  29.     window ID WREN CLOSE
  30.     if substr(sfile,1,pos(':',sfile)) = substr(dfile,1,pos(':',dfile)) then
  31.         ctype = 1
  32.     else ctype = 2
  33.  
  34. /* if the file exists at the destination then put up a requester to allow
  35. the user to decide on the action */
  36.  
  37.     if exists(dfile) & (type > 0) then do
  38.         request ID MDIR TITLE '" "' GADGETS '"_OK|_CANCEL"' '\033bFile already exists!\033n Do you wish to overwrite?'
  39.         select
  40.             when result = 0 then exit
  41.             when result = 1 then nop
  42.             otherwise nop
  43.         end
  44.     end
  45.  
  46.     call file portname ndir ctype sfile';'dfile
  47. end
  48.  
  49. /* find next selected file */
  50.  
  51. dirlist ID DIR||ndir
  52. sfile = result
  53.  
  54. /* if there is no selected file then reread dirlist and return */
  55.  
  56. if sfile = '' then do
  57.     check ID ICN||ndir
  58.     flag = result
  59.     dirlist ID DIR||ndir REREAD ATTRS Dirlist_RejectIcons flag
  60.     dirlist ID DIR||(3-ndir) REREAD ATTRS Dirlist_RejectIcons flag
  61.     exit
  62. end
  63.  
  64. /* determine a destination file name.  Of course the user will be 
  65.    free to change this in the requester created below. */
  66.  
  67. dirlist ID DIR||(3-ndir) ATTRS Dirlist_Directory
  68. ddir = import(d2c(result))
  69. if lastpos('/',ddir) ~= length(ddir) then do
  70.     if lastpos(':',ddir) ~= length(ddir) then ddir = ddir'/'
  71. end
  72. if lastpos('/',sfile) ~= 0 then dfile = ddir||substr(sfile,lastpos('/',sfile)+1)
  73. else dfile = ddir||substr(sfile,lastpos(':',sfile)+1)
  74.  
  75. /* put up a requester to allow the user to change the destination
  76.    file name.  Also allows the user to cancel the operation.  Note
  77.    that the string gadget command is set to this macro thereby setting
  78.    up a recursive loop.  This is the only way to handle multiple files
  79.    since all operations, in MUIRexx, are asyncronous. */
  80.  
  81. window ID WREN
  82.     group HORIZ
  83.         label '"rename 'sfile' to "'
  84.         string COMMAND '"muidir:renfile 'portname' ['sfile'] [%s]"' CONTENT dfile
  85.     endgroup
  86.     group HORIZ
  87.         space HORIZ
  88.         button ATTRS Weight 0 COMMAND '"window ID WREN CLOSE"' PORT portname LABEL 'Cancel'
  89.     endgroup
  90. endwindow
  91.  
  92. exit
  93.